#pragma once
#include "../lua/ELuna.h"
#include "../libmaper/_cmacro.h"
#include "../libmaper/_cpp.h"

class cWdf
{
public:
	static cWdf* getDye();
	static cWdf* getMp3();
	static cWdf* getWav();
	static cWdf* getSmap();
	~cWdf();

	static bool isWdf(const std::string &filename);

	bool open(const std::string &filename);

	void close();

	struct sIndex { uint uid, offset, size; };

	const sIndex* search2(uint uid);

	const sIndex* getIndexs() const;

	int getIndexsCount() const;

	const char* getData(const sIndex *idx, std::ifstream &ifile, bool isJudgeSp);

	const char* getData(const sIndex *idx, bool isJudgeSp);

	const char* getData(uint uid, int &size);

	const char* getData(uint uid, std::ifstream &ifile);

protected:
	std::string _filename;

	const sIndex *_indexs = nullptr;

	int _indexsCount = 0;
};


extern lua_State *L;
class LuaWdf : public cWdf
{
public:
	LuaWdf();
	~LuaWdf();

	bool load(const char* filename);
	ELuna::LuaTable getData(uint cid);
	ELuna::LuaTable getIndex(uint cid);
};

